<!-- 产品管理 -->
<div class="inner wrp wrp_data_box" id="table_item">
    <div style="display:none;" class="page_global_tips" id="binding_limit_hint"></div>
    <div class="data_box_hd js_all" id="js_mobile">
        <div id="item_tab_nav" class="label_tab">
            <a href="javascript:void(0);" data-url="{% url "smErp:create_product" %}" class="btn js_create jsUrlLink btn_disabled" target="_self">
                <span>创建产品</span>
            </a>
            <div class="bubble_tips bubble_left">
                <div class="bubble_tips_inner">
                    <p class="mass_send_tips" id="tips1">
                        <span>还可创建0个产品</span>
                    </p>
                </div>
                <i class="bubble_tips_arrow out"></i>
                <i class="bubble_tips_arrow in"></i>
            </div>
        </div>
    </div>

    <div class="data_box_bd js_all">
        <div class="table_wrp app_list">
            <!-- 产品列表 -->
            <table class="table mp_account" id="product_tb" cellspacing="0">
                <thead class="thead">
                <tr>
                    <th class="table_cell content">产品名称</th>
                    <th class="table_cell content">所属品牌</th>
                    <th class="table_cell status">状态</th>
                    {#<th class="table_cell type">帐号类型</th>#}
                    <th class="table_cell opr">操作</th>
                </tr>
                </thead>
                <tbody class="tbody" id="product_table_bd">
                <tr>
                    <td colspan="4">
                        <p class="empty_tips">暂无数据</p>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
{% block footscript %}
    <script>
        function getCookie(c_name)
        {
            if (document.cookie.length>0)
            {
                c_start=document.cookie.indexOf(c_name + "=");
                if (c_start!=-1)
                {
                    c_start=c_start + c_name.length+1;
                    c_end=document.cookie.indexOf(";",c_start);
                    if (c_end==-1) c_end=document.cookie.length;
                    return unescape(document.cookie.substring(c_start,c_end))
                }
            }
            return ""
        }
        function show_product_list(){
            // 通过接口获取品牌列表
                $.ajax({
                    type: 'POST',
                    url: '{% url "smErp:manage_product" %}',
                    headers:{ "X-CSRFtoken":getCookie("csrftoken")},
                    dataType: 'json',
                    success: function(data){
                        if (data.result == 0) {
                            console.log(data);
                            // 成功显示成功
                            if(data.can_product_nums > 0){
                                $("#item_tab_nav").children("a").attr("href", '{% url "smErp:create_product" %}').attr("data-url", '{% url "smErp:create_product" %}');
                                $("#item_tab_nav").children("a").removeClass("btn_disabled").addClass("btn_primary");
                            }else{
                                $("#item_tab_nav").children("a").attr("href", 'javascript:;').attr("data-url", '');
                                $("#item_tab_nav").children("a").removeClass("btn_primary").addClass("btn_disabled");
                            }
                            if(data.product_list.length > 0){
                                // 清空表体
                                $("#product_table_bd").empty();
                                var product_list = data.product_list ;
                                for(i = 0 ; i < product_list.length; i++){
                                    var html = '<tr style="border-bottom: 1px solid #e6e7ec;">' +
                                                '<td colspan="1"><p class="table_cell content">' + product_list[i].name + '</p></td><td colspan="1"><p class="table_cell content">' +
                                                product_list[i].brandname + '</p></td><td colspan="1"><p class="table_cell content">' + product_list[i].check_status +
                                                '</p></td><td colspan="1"><p class="table_cell opr"><a href="/smErp/product/info/' + product_list[i].id + '/">查看详情</a><br>' +
                                                '<a href="javascript:void(0);" onclick="goto_buy_suma()">购买溯码</a><br><a href="javascript:void(0);" onclick="goto_publish_suma()">发布溯码</a></p></td></tr>';
                                    $("#product_table_bd").append(html);
                                }
                                $("#product_table_bd").append('<tr><td colspan="4"><p class="empty_tips"></p></td></tr>');
                            }
                            $("#item_tab_nav").children("a").children("span").html("创建产品");
                            $("#tips1").children("span").html("还可创建" + data.can_product_nums + "个产品");
                        } else {
                            //提示层
                            layer.msg(data.reason);
                        }
                    }
                });
        }
        show_product_list();
    </script>
{% endblock %}




